import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'

const routerList: Array<RouteRecordRaw> = [];

/**
 * 动态引入路由
 * @param r
 */
function importALl(r: any) {

  r.keys().forEach(
      (key: any)=> {
        routerList.push(r(key).default)
      }
  );
}

importALl(require.context('./routes/',false,/\.routers.ts/));


const routes: Array<RouteRecordRaw> = [
  ...routerList,
  {
    path: '/',
    name: 'Main',
    meta: { transition: 'slide-right' },
    component: () => import('../views/Main.vue')
  }

]

const router = createRouter({
  history: createWebHistory(),
  routes
})

export default router
